#include "Camera.hpp"

Camera* Camera::m_singleCamera;

Camera::Camera() {
	m_position = m_lookAt = m_speed = glm::vec3(0,0,0);
	m_singleCamera = this;
	m_clippingDistance = 5000.0;
}

Camera* Camera::getCamera() {
	return m_singleCamera;
}

void Camera::initializeViewport() {
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(cameraAngle, 1.f, 1.0f, 5000.f);
	glMatrixMode(GL_MODELVIEW);
}

void Camera::setPosition(glm::vec3 position_) {
	m_position = position_;
}

void Camera::setLookAt(glm::vec3 lookAt_) {
	m_lookAt = lookAt_;
}


void Camera::setViewport() {
	glViewport(0.0, 0.0, 1024.0, 768.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(cameraAngle, 1.f, 1.0f, m_clippingDistance);
	gluLookAt(m_position.x, m_position.y, m_position.z, m_lookAt.x, m_lookAt.y, m_lookAt.z, 0.f, 0.f, 1.f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

void Camera::setReflectViewport() {
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(cameraAngle, 1.f, 1.0f, m_clippingDistance);
	gluLookAt(m_position.x, m_position.y, -m_position.z, m_lookAt.x, m_lookAt.y, m_lookAt.z, 0.f, 0.f, 1.f);
	glMatrixMode(GL_MODELVIEW);
}

void Camera::translate(glm::vec3 translationVector) {
	m_position += translationVector;
	m_lookAt += translationVector;
	setViewport();
}

void Camera::setSpeed(glm::vec3 speed_) { 
	m_speed = speed_;
}

void Camera::update(float time) {
	translate(time * m_speed);
}


